package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.ContentService;
import com.dongdongshop.vo.ContentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    @GetMapping("getAllContent")
    public Result getAllContent() {
        List<ContentVO> voList = contentService.getAllContent();
        return Result.OK().setData(voList);
    }

    @PostMapping("addContent")
    public Result addContent(@RequestBody ContentVO contentVO) {
        int i = contentService.addContent(contentVO);
        if (i >= 1) {
            return Result.OK();
        }
        return Result.FAIL();
    }

    @PostMapping("getContentById/{id}")
    public Result getContentById(@PathVariable("id") Long id) {
        ContentVO contentVO = contentService.getContentById(id);
        return Result.OK().setData(contentVO);
    }

    @PostMapping("updateContent")
    public Result updateContent(@RequestBody ContentVO contentVO) {
        int i = contentService.updateContent(contentVO);
        if (i >= 1) {
            return Result.OK();
        }
        return Result.FAIL();
    }

    @PostMapping("deleteBatch")
    public Result deleteBatch(@RequestBody List<Long> ids) {
        int i = contentService.deleteBatch(ids);
        if (i >= 1) {
            return Result.OK();
        }
        return Result.FAIL();
    }

    @PostMapping("getAdvertisingByOrder")
    public Result getAdvertisingByOrder(@RequestParam Integer flag) {
        List<ContentVO> voList = contentService.getAdvertisingByOrder(flag);
        return Result.OK().setData(voList);
    }

    /*@PostMapping("getFavoriteByOrder")
    public Result getFavoriteByOrder() {
        List<ContentVO> voList = contentService.getFavoriteByOrder();
        return Result.OK().setData(voList);
    }

    @PostMapping("getRecommendByOrder")
    public Result getRecommendByOrder() {
        List<ContentVO> voList = contentService.getRecommendByOrder();
        return Result.OK().setData(voList);
    }

    @PostMapping("getIntersertByOrder")
    public Result getIntersertByOrder() {
        List<ContentVO> voList = contentService.getIntersertByOrder();
        return Result.OK().setData(voList);
    }*/

}
